<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Project_content extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->admin->isLogin ( site_url ( 'login' ) );
		$this->load->model ( 'project_content_model' );
		$this->load->model('user_model');
	}
	public function index($pid=1,$page=1){
		$whereArr = array('pid'=>$pid,'status'=>1);
		$count = $this->project_content_model->count ( $whereArr );
		$params = array(
				"url_template" => site_url ( "Project_content/index/{$pid}/{page}" ),
				"page_count" => $count,
				"page_now" => $page,
				"page_size" => 10
		);
		$params["total_pages"] = ceil ( $params['page_count'] / $params['page_size'] );
		$this->load->library ( 'paging', $params );
		$project_content_list = $this->project_content_model->result ( $whereArr, $page, $params['page_size'] );
		$data['project_content_list'] = $project_content_list;
		$this->load->view("project_content_index",$data);
	}
	/*
	 *删除众创项目内容
	 */
	public function del($pcid=1){
		$whereArr = array("pcid"=>$pcid);
		$dataArr = array("status"=>0);
		$result = $this->project_content_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "众创项目内容删除成功!";
		}else{
			$data['status'] = 0;
			$data['info'] = "众创项目内容删除失败!";
		}
		echo json_encode($data);
	}
	/*
	 *删除多个众创项目内容 
	 */
	public function duodel(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("status"=>0);
			$result=$this->project_content_model->update_in($dataArr,'pcid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'众创项目内容删除成功!');
			}else{
				$flag = array('status'=>0,'info'=>'众创项目内容删除失败!');
			}
		}
		echo json_encode($flag);
	}
	/*
	 *单个众创项目内容通过审核操作
	 */
	public function okcheck($pcid=1){
		$whereArr = array("pcid"=>$pcid);
		$dataArr = array("check"=>3);
		$result = $this->project_content_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "众创项目内容通过审核成功!";
		}else{
			$data['status'] = 0;
			$data['info'] = "众创项目内容通过审核失败!";
		}
		echo json_encode($data);
	}
	/*
	 *众创项目内容不通过审核操作 
	 */
	public function nocheck($pcid=1){
		$whereArr = array("pcid"=>$pcid);
		$dataArr = array("check"=>2);
		$result = $this->project_content_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "众创项目内容不通过审核成功!";
		}else{
			$data['status'] = 0;
			$data['info'] = "众创项目内容不通过审核失败!";
		}
		echo json_encode($data);
	}
	/*
	 *多个众创项目内容通过审核操作
	 */
	public function duocheck(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("check"=>3);
			$result=$this->project_content_model->update_in($dataArr,'pcid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'众创项目内容通过审核成功!');
			}else{
				$flag = array('status'=>0,'info'=>'众创项目内容通过审核失败!');
			}
		}
		echo json_encode($flag);
	}
	/*
	 *多个众创项目内容不通过审核操作
	 */
	public function duonocheck(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("check"=>2);
			$result=$this->project_content_model->update_in($dataArr,'pcid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'众创项目内容不通过审核成功!');
			}else{
				$flag = array('status'=>0,'info'=>'众创项目内容不通过审核失败!');
			}
		}
		echo json_encode($flag);
	}
}